package com.powerteam.controller;

import com.alibaba.fastjson.JSON;
import com.powerteam.interceptor.annotation.RequireSession;
import com.powerteam.model.sys.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import javax.servlet.http.HttpSession;

/**
 * 权限控制校验
 *
 * @author jinming.zhang
 * @version 0.0.1
 * @date 2021/12/30
 */
@Slf4j
@Controller
@RequireSession
public class AuthorizedController {


    @Autowired
    private HttpSession session;

    /**
     * 从session中获取登录的用户信息
     *
     * @return 用户信息
     */
    public User getUser() {

        User user = (User) session.getAttribute("User");
        log.info("AuthorizedController getUser 获取用户信息 结果0:{}", JSON.toJSON(user));

        return user;
    }

}
